//
//  ITTabBarController.m
//  coderSinaWeiBo24
//
//  Created by 张雪雪 on 16/3/21.
//  Copyright © 2016年 www.xue.com. All rights reserved.
//

#import "ITTabBarController.h"
#import "ITTabBar.h"
#import "ITHomeViewCtrl.h"
#import "ITNavigationController.h"

@interface ITTabBarController ()<ITTabBarDelegate>

@end

@implementation ITTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    UITabBarController *homeCv = [[UITabBarController alloc]init];
//    
//    homeCv.title = @"首页";
//    homeCv.tabBarItem.image = [UIImage imageNamed:@"tabbar_home"];
//    homeCv.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_home_selected"];
//    [self addChildViewController:homeCv];
    //初始化一个uibutton
    ITTabBar *tabbar = [[ITTabBar alloc]init];
    
    tabbar.delegate = self;
    //因为是只读属性,所以通过kvc的方式去赋值
    [self setValue:tabbar forKeyPath:@"tabBar"];
    
    [self addChildController];
    
}
-(void)addChildController{


    ITHomeViewCtrl *homeCtrl = [ITHomeViewCtrl new];
    
    [self addChildViewController:homeCtrl imageName:@"tabbar_home" title:@"首页"];
    //消息
    UITableViewController *msgCtrl = [UITableViewController new];
    [self addChildViewController:msgCtrl imageName:@"tabbar_message_center" title:@"消息"];
    
    UITableViewController *discoverCtrl = [UITableViewController new];
    [self addChildViewController:discoverCtrl imageName:@"tabbar_discover" title:@"发现"];
    UITableViewController *profileCtrl = [UITableViewController new];
    [self addChildViewController:profileCtrl imageName:@"tabbar_profile" title:@"我"];


}

-(void)addChildViewController:(UIViewController *)childCv imageName:(NSString *)imageName title:(NSString *)title{
    
    //设置选中与未选中的图片-->指定一下渲染模式-->图片以原样的方式显示出来
    childCv.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childCv.tabBarItem.selectedImage =[[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //设置标题
//    childCv.tabBarItem.title = title;
//    childCv.navigationItem.title = title;
    
    childCv.title = title;
    
    //指定一下属性
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    //指定设定选中状态文字的颜色
    [childCv.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    //添加导航栏
    ITNavigationController *navCtrl = [[ITNavigationController alloc]initWithRootViewController:childCv];
    
    
    [self addChildViewController:navCtrl];
}

- (void)tabBar:(ITTabBar *)tabBar didSelectPlusButton:(UIButton *)button{
    NSLog(@"加号按钮点击了");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
